import test.Yewu;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.util.ASMifier;
import org.objectweb.asm.util.Textifier;
import org.objectweb.asm.util.TraceMethodVisitor;

import java.io.InputStream;
import java.util.List;

public class test001 {
    public static void main(String[] args) throws Exception {
        InputStream resource = Yewu.class.getResourceAsStream(Yewu.class.getSimpleName() + ".class");

        byte[] bytes = new byte[resource.available()];
        resource.read(bytes);

        String method = "main";
        String desc = "([Ljava/lang/String;)V";

        int api = Opcodes.ASM9;
        ClassReader cr = new ClassReader(bytes);

        ClassVisitor cv = null;
        ASMifier printer = new ASMifier();
        {
            MyClassVisitor myClassVisitor = new MyClassVisitor(api, cv);
            myClassVisitor.setDesc(desc);
            myClassVisitor.setMethodName(method);

            TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(printer);
            myClassVisitor.setMethodVisitor(traceMethodVisitor);

            cv = myClassVisitor;
        }
        Textifier printer2 = new Textifier();
        {
            MyClassVisitor myClassVisitor2 = new MyClassVisitor(api, cv);
            myClassVisitor2.setDesc(desc);
            myClassVisitor2.setMethodName(method);
            TraceMethodVisitor traceMethodVisitor2 = new TraceMethodVisitor(printer2);
            myClassVisitor2.setMethodVisitor(traceMethodVisitor2);

//            cv = myClassVisitor2;
        }


        {
            MyClassVisitor myClassVisitor = new MyClassVisitor(api, cv);
            myClassVisitor.setDesc(desc);
            myClassVisitor.setMethodName(method);
            Aop1Mv mv = new Aop1Mv(api);
            myClassVisitor.setMethodVisitor(mv);

            cv = myClassVisitor;
        }

        {
            MyClassVisitor myClassVisitor = new MyClassVisitor(api, cv);
            myClassVisitor.setDesc(desc);
            myClassVisitor.setMethodName(method);
            Aop2Mv mv = new Aop2Mv(api);
            myClassVisitor.setMethodVisitor(mv);

            cv = myClassVisitor;
        }

        {
            MyClassVisitor myClassVisitor = new MyClassVisitor(api, cv);
            myClassVisitor.setDesc(desc);
            myClassVisitor.setMethodName(method);
            Aop3Mv mv = new Aop3Mv(api);
            myClassVisitor.setMethodVisitor(mv);

            cv = myClassVisitor;
        }

        cr.accept(cv, ClassReader.SKIP_FRAMES);


        List<Object> text = printer.text;
        text.stream().forEach(System.out::print);


    }
}
